/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Actions;

/**
 *
 * @author Bryan
 */
import Captcha.CaptchaServlet;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;

public class CaptchaAction extends ActionSupport {

    private Register reg = new Register();

    @Override
    public String execute() throws Exception {
        try {
            HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
            Boolean isResponseCorrect = Boolean.FALSE;
            javax.servlet.http.HttpSession session = request.getSession();
            String parm = request.getParameter("j_captcha_response");
            String c = (String) session.getAttribute(CaptchaServlet.CAPTCHA_KEY);
            if (!parm.equals(c)) {
                addActionError("Invalid Code! Please try again!");
                return ERROR;
            } else {
                return SUCCESS;
            }
        } catch (Exception e) {
            Logger.getLogger(CaptchaAction.class.getName()).log(Level.SEVERE, null, e);
            return ERROR;
        }
    }
}